/*
 * JSONUtil.java
 *
 * Copyright 2013 the original author or authors(ninglong).
 *
 * Licensed under the org.geek.common.util, Version 1.0 (the "License");
 *
 */
package org.geek.core.util;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.geek.core.base.BaseException;

/**
 * <p></p>
 * @author ninglong bhd2973@qq.com
 * @version V1.0
 */
public class JSONUtil {
	private static ObjectMapper mapper = new ObjectMapper();
	
	public static String toJson(Object value){
		try {
			return mapper.writeValueAsString(value);
		} catch (Exception e) {
			throw new BaseException(e);
		}
	}
	
	public static <T> T toJavaBean(String json,Class<T> cls){
		try {
			return mapper.readValue(json, cls);
		} catch (Exception e) {
			throw new BaseException(e);
		}
	}
	
	public static JsonNode getJsonNode(String json){
		try {
			return mapper.readTree(json);
		} catch (Exception e) {
			throw new BaseException(e);
		}
	}
}
